#include "utils.h"


namespace apollo
{
	namespace core
	{
		Utils::Utils(void)
		{
		}

		Utils::~Utils(void)
		{
		}

		QString Utils::toHexRepresentation(const char *ba, int length)
		{
			if(length <= 0 || ba == NULL)
			{
				return QString();
			}

			QString result;


			const char toHex[] = "0123456789ABCDEF";
			int i = 0;

			char tmp[4];
			tmp[2] = ' ';
			tmp[3] = '\0';
			while(i < length) {

				const char at = ba[i];
				tmp[0] =   toHex[(at >> 4) & 0x0F] ;
				tmp[1] =  toHex[at & 0x0F];
				result.append(tmp);
				++i;

			}

			return result;
		}

		void Utils::toHexRepresentation( QDebug& debug, const char *ba, int length)
		{
			if(length <= 0 || ba == NULL)
			{
				return ;
			}

			const char toHex[] = "0123456789ABCDEF";
			int i = 0;
			char result[3];
			result[2] = '\0';
			while(i < length) {
				const char at = ba[i];
				result[0] =   toHex[(at >> 4) & 0x0F] ;
				result[1] =  toHex[at & 0x0F];
				debug << result;
				++i;
			}

			return;
		}
	}}
